package testgaher;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 泛型的引入以及练习
 * User: 86184
 * Date: 2023-09-26
 * Time: 10:50
 */
public class TestArraysList2 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("haha");
        list.add("java");
        list.add("world");
        list.add("abc");

        System.out.println(list);
        System.out.println("---------------");
        for(int i = 0; i < list.size(); i++){
            String s = list.get(i);
            if(s.contains("a")){
                System.out.println(s);
            }
        }

        System.out.println("-------------------");
        for(int i = 0; i < list.size(); i++){
            String s = list.get(i);
            if(s.length() > 3){
                System.out.println(s);
            }
        }

        System.out.println("--------------------");
        for(int i = 0; i < list.size(); i+=2){
            System.out.println(list.get(i));
        }

        System.out.println("--------------------");
        String str ="";
        for(int i = 0; i < list.size(); i++){
            str += list.get(i);
            if(i < list.size()-1)
                str +=",";
        }
        System.out.println(str);

        System.out.println("---------------------");
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0; i < list.size(); i++){
            if(i < list.size() - 1)
                stringBuilder.append(list.get(i)+",");
            else
                stringBuilder.append(list.get(i));
        }
        System.out.println(stringBuilder);
    }
}
